FROM php:8.2-fpm

USER root

# Copy composer.lock and composer.json into the working directory
COPY composer.lock composer.json /var/www/backend-v5/

# Set working directory
WORKDIR /var/www/backend-v5/

# Install dependencies for the operating system software
RUN apt-get update && apt-get install -y \
    build-essential \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    locales \
    zip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    libzip-dev \
    unzip \
    git \
    libonig-dev \
    libwebp-dev \
    curl

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install extensions for php
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp
RUN docker-php-ext-install gd

# Install composer (php package manager)
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Copy existing application directory contents to the working directory
# COPY . /var/www/html

# Assign permissions of the working directory to the www-data user

# RUN chown -R www-data:www-data \
 #        /var/www/html/storage \
   #      /var/www/html/bootstrap/cache

RUN  chmod -R 775 /var/www/backend-v5

RUN  chown -R www-data:www-data /var/www/backend-v5



# Expose port 9000 and start php-fpm server (for FastCGI Process Manager)
EXPOSE 9000
